var logger = require('../../common/logger');
var tools = require('../../common/tools');
var User = require('../../proxy').User;
var validator = require('validator');

exports.verifyCode = function verifyCode(req, res) {
  var data = req.body;
  if (!data.clientType) {
    res.status(400);
    return res.send_data({
      code: 400,
      message: '缺少clientType参数'
    });
  }
  if (!data.pcode) {
    res.status(400);
    return res.send_data({
      code: 400,
      message: '缺少pcode参数'
    });
  }
  var pcode = validator.trim(data.pcode);
  User.findByUnameOrPcode({
    pcode: pcode
  }).then(function (user) {
    if (!user) {
      res.status(401);
      return res.send_data({
        code: 401,
        message: 'wrong clientType or pcode'
      });
    }
    return res.send_data({
      entities: {
        verify: true,
        plevel: user.plevel
      }
    });
  });
};
